package cn.star.jots.subject.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.subject.pojo.dto.SubjectQuery;
import cn.star.jots.subject.pojo.dto.SubjectSaveParam;
import cn.star.jots.subject.pojo.vo.SubjectVO;
import cn.star.jots.subject.service.SubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/subject")
@Api(tags = "专题管理")
@Slf4j
public class SubjectController {

    @Autowired
    SubjectService subjectService;

    @GetMapping("/select")
    @ApiOperation(value = "查询专题")
    public JsonResult selectAll(SubjectQuery subjectQuery){
        log.info("查询专题:subjectQuery={}", subjectQuery);
        List<SubjectVO> list = subjectService.selectAll(subjectQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存专题")
    public JsonResult save(SubjectSaveParam subjectSaveParam){
        log.info("保存专题:subjectSaveParam={}", subjectSaveParam);
        subjectService.save(subjectSaveParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据ID删除专题")
    public JsonResult deleteById(@PathVariable Long id){
        log.info("根据ID删除专题:id={}", id);
        subjectService.deleteById(id);
        return JsonResult.ok();
    }
}
